package cn.xspace.chatui.listener;

import android.content.Intent;
import android.util.Log;

import com.hyphenate.EMMessageListener;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.util.EMLog;
import com.xspace.android.xafcommon.appliction.BaseApplication;
import com.xspace.android.xafcommon.util.LogUtil;

import java.util.List;

/**
 * Wubj 创建于 2017/7/17.
 */
public class HxMessageListener implements EMMessageListener {

    private static final String TAG = HxMessageListener.class.getSimpleName();

    @Override
    public void onMessageReceived(List<EMMessage> messages) {
        LogUtil.e(TAG, "wubaojie>>>messageSize : " + messages.size());
        for (EMMessage message : messages) {
            LogUtil.e(TAG, "wubaojie>>>" + "onMessageReceived: \n" + message.toString());
//            Notifier.getInstance().onNewMsg(message);
            Intent intent = new Intent();
            intent.putExtra("message", message);
            intent.setAction("cn.xspace.wnx.broadreceiver.HuanXinPushReceiver");//此处的名字要和接受者的一致
            BaseApplication.mInstance.sendBroadcast(intent);
        }
    }

    @Override
    public void onCmdMessageReceived(List<EMMessage> messages) {
        Log.d(TAG, "onCmdMessageReceived() called with: messages = [" + messages + "]");
        for (EMMessage message : messages) {
            EMLog.d(TAG, "receive command message");
        }
    }

    @Override
    public void onMessageRead(List<EMMessage> list) {
        Log.d(TAG, "onMessageReadAckReceived() called with: messages = [" + list + "]");
    }

    @Override
    public void onMessageDelivered(List<EMMessage> list) {
        Log.d(TAG, "onMessageDeliveryAckReceived() called with: message = [" + list + "]");

    }

    @Override
    public void onMessageChanged(EMMessage message, Object change) {
        Log.d(TAG, "onMessageChanged() called with: message = [" + message + "], change = [" + change + "]");
    }
}
